<?php
/**
 * Controller_Action
 * 
 * 作者:  姚刚 (yaogang@the9sense.com)
 * 创建时间: 2011-03-01 22:38:34
 * 修改记录: 
 * 
 * $Id: Action.php 2 2011-03-08 01:31:19Z coosuu@gmail.com $
 */

class Controller_Action {

    protected $view;

    protected $request;

    protected $response;

    protected $front;

    public function __construct(&$front) {

        $this->front = $front;
        $this->view = $front->getView();
        $this->request = $front->getRequest();
        $this->response = $front->getResponse();
    }

    public function execute($methodName) {

        if ($this->_beforeAction($methodName)) {
            $this->$methodName();
        }

        $this->_afterAction($methodName);
    }

    protected function _beforeAction($m) {

        return true;
    }

    protected function _afterAction($m) {

        return true;
    }

    public function forward($controllerName, $actionName) {

        if (!class_exists($controllerName)) {
            throw new Controller_Exception('Controller:' . $controllerName . ' not exists.');
        }

        $obj = new $controllerName($this->front);
        $actionName .= 'Action';
        if (!method_exists($obj, $actionName)) {
            throw new Controller_Exception('Method:' . $actionName . ' not exists.');
        }

        if ($obj->_beforeAction($actionName)) {
            $obj->$actionName();
        }

        $obj->_afterAction($actionName);
    }

    public function redirect() {

    } 
}
